source("../../lib/som-utils.R")
Attaching package: 'dplyr'
The following objects are masked from 'package:stats':
filter, lag
The following objects are masked from 'package:base':
intersect, setdiff, setequal, union
source("../../lib/maps-utils.R")
Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1
mpr.set_base_path_analysis()
model <- mpr.load_model("som-273.rds.xz")
summary(model)
SOM of size 5x5 with a hexagonal topology and a bubble neighbourhood function.
The number of data layers is 1.
Distance measure(s) used: sumofsquares.
Training data included: 94881 objects.
Mean distance to the closest unit in the map: 0.766.
plot(model, type="changes")
df <- mpr.load_data("datos_mes.csv.xz")
df
summary(df)
id_estacion fecha fecha_cnt tmax
Length:94881 Length:94881 Min. : 1.000 Min. :-53.0
Class :character Class :character 1st Qu.: 4.000 1st Qu.:148.0
Mode :character Mode :character Median : 6.000 Median :198.0
Mean : 6.497 Mean :200.2
3rd Qu.: 9.000 3rd Qu.:255.0
Max. :12.000 Max. :403.0
tmin precip nevada prof_nieve
Min. :-121.00 Min. : 0.00 Min. :0.000000 Min. : 0.000
1st Qu.: 53.00 1st Qu.: 3.00 1st Qu.:0.000000 1st Qu.: 0.000
Median : 98.00 Median : 10.00 Median :0.000000 Median : 0.000
Mean : 98.86 Mean : 16.25 Mean :0.000295 Mean : 0.467
3rd Qu.: 148.00 3rd Qu.: 22.00 3rd Qu.:0.000000 3rd Qu.: 0.000
Max. : 254.00 Max. :422.00 Max. :6.000000 Max. :1834.000
longitud latitud altitud
Min. :27.82 Min. :-17.8889 Min. : 1.0
1st Qu.:38.28 1st Qu.: -5.6417 1st Qu.: 42.0
Median :40.82 Median : -3.4500 Median : 247.0
Mean :39.66 Mean : -3.4350 Mean : 418.5
3rd Qu.:42.08 3rd Qu.: 0.4914 3rd Qu.: 656.0
Max. :43.57 Max. : 4.2156 Max. :2535.0
world <- ne_countries(scale = "medium", returnclass = "sf")
spain <- subset(world, admin == "Spain")
plot(model, type="count", shape = "straight", palette.name = mpr.degrade.bleu)
NĂºmero de elementos en cada celda:
nb <- table(model$unit.classif)
print(nb)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
1198 3237 5525 4593 4643 5697 2474 4072 4881 3337 4239 5127 3658 1825 996 4992
17 18 19 20 21 22 23 24 25
3690 5179 3347 5121 4542 3323 2934 3512 2739
ComprobaciĂ³n de nodos vacĂos:
dim_model <- 5*5;
len_nb = length(nb);
empty_nodes <- dim_model != len_nb;
if (empty_nodes) {
print(paste("[Warning] Existen nodos vacĂos: ", len_nb, "/", dim_model))
}
plot(model, type="dist.neighbours", shape = "straight")
model_colnames = c("fecha_cnt", "tmax", "tmin", "longitud", "latitud", "altitud")
model_ncol = length(model_colnames)
plot(model, shape = "straight")
par(mfrow=c(3,4))
for (j in 1:model_ncol) {
plot(model, type="property", property=getCodes(model,1)[,j],
palette.name=mpr.coolBlueHotRed,
main=model_colnames[j],
cex=0.5, shape = "straight")
}
if (!empty_nodes) {
cor <- apply(getCodes(model,1), 2, mpr.weighted.correlation, w=nb, som=model)
print(cor)
}
fecha_cnt tmax tmin longitud latitud altitud
[1,] -0.1040795 -0.8454533 -0.9058925 0.5746571 0.2885151 0.33451253
[2,] 0.8750336 0.3775844 0.3295735 0.2074481 0.2792705 -0.03224658
RepresentaciĂ³n de cada variable en un mapa de factores:
if (!empty_nodes) {
par(mfrow=c(1,1))
plot(cor[1,], cor[2,], xlim=c(-1,1), ylim=c(-1,1), type="n")
lines(c(-1,1),c(0,0))
lines(c(0,0),c(-1,1))
text(cor[1,], cor[2,], labels=model_colnames, cex=0.75)
symbols(0,0,circles=1,inches=F,add=T)
}
Importancia de cada variable - varianza ponderada por el tamaño de la celda:
if (!empty_nodes) {
sigma2 <- sqrt(apply(getCodes(model,1),2,function(x,effectif)
{m<-sum(effectif*(x-weighted.mean(x,effectif))^2)/(sum(effectif)-1)},
effectif=nb))
print(sort(sigma2,decreasing=T))
}
longitud altitud tmax fecha_cnt latitud tmin
0.9603377 0.9396375 0.9329319 0.9291338 0.9262232 0.9260460
if (!empty_nodes) {
hac <- mpr.hac(model, nb)
}
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=3)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=3)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. : 13.0 Min. :-33.0 Min. : 0.000 Min. :0
1st Qu.: 4.00 1st Qu.:200.0 1st Qu.:132.0 1st Qu.: 0.000 1st Qu.:0
Median : 7.00 Median :225.0 Median :160.0 Median : 1.000 Median :0
Mean : 6.51 Mean :217.2 Mean :150.4 Mean : 7.421 Mean :0
3rd Qu.: 9.00 3rd Qu.:253.0 3rd Qu.:189.0 3rd Qu.: 8.000 3rd Qu.:0
Max. :12.00 Max. :356.0 Max. :244.0 Max. :309.000 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.89 Min. : 14.0
1st Qu.: 0.00000 1st Qu.:28.31 1st Qu.:-16.50 1st Qu.: 25.0
Median : 0.00000 Median :28.44 Median :-16.33 Median : 35.0
Mean : 0.03075 Mean :28.37 Mean :-16.05 Mean : 520.9
3rd Qu.: 0.00000 3rd Qu.:28.48 3rd Qu.:-15.39 3rd Qu.: 632.0
Max. :46.00000 Max. :28.95 Max. :-13.60 Max. :2371.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. :-53 Min. :-121.00 Min. : 0.00
1st Qu.: 2.000 1st Qu.:123 1st Qu.: 26.00 1st Qu.: 6.00
Median : 3.000 Median :156 Median : 57.00 Median : 14.00
Mean : 3.184 Mean :153 Mean : 54.15 Mean : 19.43
3rd Qu.: 4.000 3rd Qu.:185 3rd Qu.: 83.00 3rd Qu.: 27.00
Max. :12.000 Max. :307 Max. : 191.00 Max. :371.00
nevada prof_nieve longitud latitud
Min. :0.00000 Min. : 0.000 Min. :35.28 Min. :-8.6494
1st Qu.:0.00000 1st Qu.: 0.000 1st Qu.:39.01 1st Qu.:-5.3456
Median :0.00000 Median : 0.000 Median :41.11 Median :-3.1742
Mean :0.00054 Mean : 1.221 Mean :40.63 Mean :-2.6674
3rd Qu.:0.00000 3rd Qu.: 0.000 3rd Qu.:42.36 3rd Qu.: 0.4914
Max. :6.00000 Max. :1834.000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 61.0
Median : 412.0
Mean : 529.8
3rd Qu.: 775.0
Max. :2535.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. : 8.0 Min. :-110.0 Min. : 0.00
1st Qu.: 7.000 1st Qu.:182.0 1st Qu.: 86.0 1st Qu.: 2.00
Median : 9.000 Median :236.0 Median : 128.0 Median : 9.00
Mean : 8.701 Mean :229.4 Mean : 121.9 Mean : 15.28
3rd Qu.:11.000 3rd Qu.:283.0 3rd Qu.: 163.0 3rd Qu.: 21.00
Max. :12.000 Max. :403.0 Max. : 254.0 Max. :422.00
nevada prof_nieve longitud latitud
Min. :0.0000000 Min. : 0.0000 Min. :35.28 Min. :-8.6494
1st Qu.:0.0000000 1st Qu.: 0.0000 1st Qu.:38.95 1st Qu.:-4.8458
Median :0.0000000 Median : 0.0000 Median :40.95 Median :-2.3308
Mean :0.0001704 Mean : 0.0217 Mean :40.50 Mean :-2.2992
3rd Qu.:0.0000000 3rd Qu.: 0.0000 3rd Qu.:42.08 3rd Qu.: 0.5706
Max. :3.0000000 Max. :59.0000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 43.0
Median : 185.0
Mean : 331.1
3rd Qu.: 611.0
Max. :1894.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=4)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=4)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. : 13.0 Min. :-33.0 Min. : 0.000 Min. :0
1st Qu.: 4.00 1st Qu.:200.0 1st Qu.:132.0 1st Qu.: 0.000 1st Qu.:0
Median : 7.00 Median :225.0 Median :160.0 Median : 1.000 Median :0
Mean : 6.51 Mean :217.2 Mean :150.4 Mean : 7.421 Mean :0
3rd Qu.: 9.00 3rd Qu.:253.0 3rd Qu.:189.0 3rd Qu.: 8.000 3rd Qu.:0
Max. :12.00 Max. :356.0 Max. :244.0 Max. :309.000 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.89 Min. : 14.0
1st Qu.: 0.00000 1st Qu.:28.31 1st Qu.:-16.50 1st Qu.: 25.0
Median : 0.00000 Median :28.44 Median :-16.33 Median : 35.0
Mean : 0.03075 Mean :28.37 Mean :-16.05 Mean : 520.9
3rd Qu.: 0.00000 3rd Qu.:28.48 3rd Qu.:-15.39 3rd Qu.: 632.0
Max. :46.00000 Max. :28.95 Max. :-13.60 Max. :2371.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip
Min. :1.000 Min. : -4.0 Min. :-89.00 Min. : 0.0
1st Qu.:2.000 1st Qu.:129.0 1st Qu.: 30.00 1st Qu.: 5.0
Median :3.000 Median :159.0 Median : 59.00 Median : 13.0
Mean :2.891 Mean :159.2 Mean : 57.76 Mean : 18.1
3rd Qu.:4.000 3rd Qu.:187.0 3rd Qu.: 84.00 3rd Qu.: 24.0
Max. :7.000 Max. :307.0 Max. :191.00 Max. :371.0
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.00000 Min. :35.28 Min. :-8.6494
1st Qu.:0.000000 1st Qu.: 0.00000 1st Qu.:38.95 1st Qu.:-5.5975
Median :0.000000 Median : 0.00000 Median :40.96 Median :-3.5556
Mean :0.000587 Mean : 0.09429 Mean :40.51 Mean :-2.8809
3rd Qu.:0.000000 3rd Qu.: 0.00000 3rd Qu.:42.24 3rd Qu.: 0.0406
Max. :6.000000 Max. :75.00000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 52.0
Median : 336.0
Mean : 391.9
3rd Qu.: 667.0
Max. :1572.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. : 8.0 Min. :-110.0 Min. : 0.00
1st Qu.: 7.000 1st Qu.:182.0 1st Qu.: 86.0 1st Qu.: 2.00
Median : 9.000 Median :236.0 Median : 128.0 Median : 9.00
Mean : 8.701 Mean :229.4 Mean : 121.9 Mean : 15.28
3rd Qu.:11.000 3rd Qu.:283.0 3rd Qu.: 163.0 3rd Qu.: 21.00
Max. :12.000 Max. :403.0 Max. : 254.0 Max. :422.00
nevada prof_nieve longitud latitud
Min. :0.0000000 Min. : 0.0000 Min. :35.28 Min. :-8.6494
1st Qu.:0.0000000 1st Qu.: 0.0000 1st Qu.:38.95 1st Qu.:-4.8458
Median :0.0000000 Median : 0.0000 Median :40.95 Median :-2.3308
Mean :0.0001704 Mean : 0.0217 Mean :40.50 Mean :-2.2992
3rd Qu.:0.0000000 3rd Qu.: 0.0000 3rd Qu.:42.08 3rd Qu.: 0.5706
Max. :3.0000000 Max. :59.0000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 43.0
Median : 185.0
Mean : 331.1
3rd Qu.: 611.0
Max. :1894.0
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. :-53.00 Min. :-121.0 Min. : 0.00
1st Qu.: 4.000 1st Qu.: 30.00 1st Qu.: -31.0 1st Qu.: 17.00
Median : 6.000 Median : 74.00 Median : 8.0 Median : 30.00
Mean : 6.541 Mean : 82.34 Mean : 12.7 Mean : 34.69
3rd Qu.:10.000 3rd Qu.:133.00 3rd Qu.: 58.0 3rd Qu.: 47.00
Max. :12.000 Max. :229.00 Max. : 134.0 Max. :180.00
nevada prof_nieve longitud latitud altitud
Min. :0 Min. : 0.00 Min. :40.78 Min. :-4.0103 Min. :1405
1st Qu.:0 1st Qu.: 0.00 1st Qu.:40.78 1st Qu.:-4.0103 1st Qu.:1894
Median :0 Median : 0.00 Median :42.38 Median : 0.8842 Median :2143
Mean :0 Mean : 14.14 Mean :41.95 Mean :-0.2193 Mean :2110
3rd Qu.:0 3rd Qu.: 0.00 3rd Qu.:42.53 3rd Qu.: 1.5242 3rd Qu.:2316
Max. :0 Max. :1834.00 Max. :42.77 Max. : 2.4378 Max. :2535
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=5)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=5)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. : 13.0 Min. :-33.0 Min. : 0.000 Min. :0
1st Qu.: 4.00 1st Qu.:200.0 1st Qu.:132.0 1st Qu.: 0.000 1st Qu.:0
Median : 7.00 Median :225.0 Median :160.0 Median : 1.000 Median :0
Mean : 6.51 Mean :217.2 Mean :150.4 Mean : 7.421 Mean :0
3rd Qu.: 9.00 3rd Qu.:253.0 3rd Qu.:189.0 3rd Qu.: 8.000 3rd Qu.:0
Max. :12.00 Max. :356.0 Max. :244.0 Max. :309.000 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :27.82 Min. :-17.89 Min. : 14.0
1st Qu.: 0.00000 1st Qu.:28.31 1st Qu.:-16.50 1st Qu.: 25.0
Median : 0.00000 Median :28.44 Median :-16.33 Median : 35.0
Mean : 0.03075 Mean :28.37 Mean :-16.05 Mean : 520.9
3rd Qu.: 0.00000 3rd Qu.:28.48 3rd Qu.:-15.39 3rd Qu.: 632.0
Max. :46.00000 Max. :28.95 Max. :-13.60 Max. :2371.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip
Min. :1.000 Min. : -4.0 Min. :-89.00 Min. : 0.0
1st Qu.:2.000 1st Qu.:129.0 1st Qu.: 30.00 1st Qu.: 5.0
Median :3.000 Median :159.0 Median : 59.00 Median : 13.0
Mean :2.891 Mean :159.2 Mean : 57.76 Mean : 18.1
3rd Qu.:4.000 3rd Qu.:187.0 3rd Qu.: 84.00 3rd Qu.: 24.0
Max. :7.000 Max. :307.0 Max. :191.00 Max. :371.0
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.00000 Min. :35.28 Min. :-8.6494
1st Qu.:0.000000 1st Qu.: 0.00000 1st Qu.:38.95 1st Qu.:-5.5975
Median :0.000000 Median : 0.00000 Median :40.96 Median :-3.5556
Mean :0.000587 Mean : 0.09429 Mean :40.51 Mean :-2.8809
3rd Qu.:0.000000 3rd Qu.: 0.00000 3rd Qu.:42.24 3rd Qu.: 0.0406
Max. :6.000000 Max. :75.00000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 52.0
Median : 336.0
Mean : 391.9
3rd Qu.: 667.0
Max. :1572.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. :164 Min. : 65 Min. : 0.00 Min. :0
1st Qu.: 6.000 1st Qu.:242 1st Qu.:129 1st Qu.: 1.00 1st Qu.:0
Median : 7.000 Median :274 Median :154 Median : 6.00 Median :0
Mean : 7.206 Mean :272 Mean :155 Mean : 10.92 Mean :0
3rd Qu.: 8.000 3rd Qu.:302 3rd Qu.:181 3rd Qu.: 15.00 3rd Qu.:0
Max. :12.000 Max. :403 Max. :254 Max. :422.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :35.28 Min. :-8.6494 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:38.88 1st Qu.:-4.8458 1st Qu.: 35.0
Median : 0.00000 Median :40.93 Median :-2.0392 Median : 127.0
Mean : 0.00361 Mean :40.46 Mean :-2.2614 Mean : 300.7
3rd Qu.: 0.00000 3rd Qu.:42.07 3rd Qu.: 0.5706 3rd Qu.: 541.0
Max. :38.00000 Max. :43.57 Max. : 4.2156 Max. :1894.0
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. :-53.00 Min. :-121.0 Min. : 0.00
1st Qu.: 4.000 1st Qu.: 30.00 1st Qu.: -31.0 1st Qu.: 17.00
Median : 6.000 Median : 74.00 Median : 8.0 Median : 30.00
Mean : 6.541 Mean : 82.34 Mean : 12.7 Mean : 34.69
3rd Qu.:10.000 3rd Qu.:133.00 3rd Qu.: 58.0 3rd Qu.: 47.00
Max. :12.000 Max. :229.00 Max. : 134.0 Max. :180.00
nevada prof_nieve longitud latitud altitud
Min. :0 Min. : 0.00 Min. :40.78 Min. :-4.0103 Min. :1405
1st Qu.:0 1st Qu.: 0.00 1st Qu.:40.78 1st Qu.:-4.0103 1st Qu.:1894
Median :0 Median : 0.00 Median :42.38 Median : 0.8842 Median :2143
Mean :0 Mean : 14.14 Mean :41.95 Mean :-0.2193 Mean :2110
3rd Qu.:0 3rd Qu.: 0.00 3rd Qu.:42.53 3rd Qu.: 1.5242 3rd Qu.:2316
Max. :0 Max. :1834.00 Max. :42.77 Max. : 2.4378 Max. :2535
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip
Min. : 7.00 Min. : 8.0 Min. :-110.00 Min. : 0.00
1st Qu.:10.00 1st Qu.:129.0 1st Qu.: 41.00 1st Qu.: 6.00
Median :11.00 Median :166.0 Median : 73.00 Median : 15.00
Mean :10.97 Mean :164.8 Mean : 71.61 Mean : 21.91
3rd Qu.:12.00 3rd Qu.:200.0 3rd Qu.: 102.00 3rd Qu.: 30.00
Max. :12.00 Max. :284.0 Max. : 187.00 Max. :299.00
nevada prof_nieve longitud latitud
Min. :0.0000000 Min. : 0.00000 Min. :35.28 Min. :-8.6494
1st Qu.:0.0000000 1st Qu.: 0.00000 1st Qu.:38.99 1st Qu.:-4.8500
Median :0.0000000 Median : 0.00000 Median :40.96 Median :-2.4544
Mean :0.0004291 Mean : 0.04915 Mean :40.55 Mean :-2.3567
3rd Qu.:0.0000000 3rd Qu.: 0.00000 3rd Qu.:42.08 3rd Qu.: 0.4942
Max. :3.0000000 Max. :59.00000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 47.0
Median : 261.0
Mean : 377.3
3rd Qu.: 667.0
Max. :1572.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=6)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=6)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
df.cluster06 <- subset(df, cluster==6)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster06 <- select(df.cluster06, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 13 Min. :-33.00 Min. : 0.00 Min. :0
1st Qu.: 4.000 1st Qu.: 94 1st Qu.: 23.00 1st Qu.: 0.00 1st Qu.:0
Median : 7.000 Median :128 Median : 50.00 Median : 3.00 Median :0
Mean : 6.603 Mean :138 Mean : 60.53 Mean : 11.63 Mean :0
3rd Qu.:10.000 3rd Qu.:183 3rd Qu.: 98.00 3rd Qu.: 14.00 3rd Qu.:0
Max. :12.000 Max. :253 Max. :159.00 Max. :309.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :28.31 Min. :-16.5 Min. :2371
1st Qu.: 0.0000 1st Qu.:28.31 1st Qu.:-16.5 1st Qu.:2371
Median : 0.0000 Median :28.31 Median :-16.5 Median :2371
Mean : 0.1753 Mean :28.31 Mean :-16.5 Mean :2371
3rd Qu.: 0.0000 3rd Qu.:28.31 3rd Qu.:-16.5 3rd Qu.:2371
Max. :46.0000 Max. :28.31 Max. :-16.5 Max. :2371
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip
Min. :1.000 Min. : -4.0 Min. :-89.00 Min. : 0.0
1st Qu.:2.000 1st Qu.:129.0 1st Qu.: 30.00 1st Qu.: 5.0
Median :3.000 Median :159.0 Median : 59.00 Median : 13.0
Mean :2.891 Mean :159.2 Mean : 57.76 Mean : 18.1
3rd Qu.:4.000 3rd Qu.:187.0 3rd Qu.: 84.00 3rd Qu.: 24.0
Max. :7.000 Max. :307.0 Max. :191.00 Max. :371.0
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.00000 Min. :35.28 Min. :-8.6494
1st Qu.:0.000000 1st Qu.: 0.00000 1st Qu.:38.95 1st Qu.:-5.5975
Median :0.000000 Median : 0.00000 Median :40.96 Median :-3.5556
Mean :0.000587 Mean : 0.09429 Mean :40.51 Mean :-2.8809
3rd Qu.:0.000000 3rd Qu.: 0.00000 3rd Qu.:42.24 3rd Qu.: 0.0406
Max. :6.000000 Max. :75.00000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 52.0
Median : 336.0
Mean : 391.9
3rd Qu.: 667.0
Max. :1572.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. : 87.0 Min. : 64.0 Min. : 0.000 Min. :0
1st Qu.: 3.00 1st Qu.:212.0 1st Qu.:150.0 1st Qu.: 0.000 1st Qu.:0
Median : 6.00 Median :233.0 Median :168.0 Median : 1.000 Median :0
Mean : 6.49 Mean :233.8 Mean :169.3 Mean : 6.536 Mean :0
3rd Qu.: 9.00 3rd Qu.:259.0 3rd Qu.:196.0 3rd Qu.: 7.000 3rd Qu.:0
Max. :12.00 Max. :356.0 Max. :244.0 Max. :145.000 Max. :0
prof_nieve longitud latitud altitud
Min. :0.0000000 Min. :27.82 Min. :-17.89 Min. : 14.0
1st Qu.:0.0000000 1st Qu.:28.05 1st Qu.:-16.56 1st Qu.: 25.0
Median :0.0000000 Median :28.46 Median :-16.26 Median : 33.0
Mean :0.0003511 Mean :28.38 Mean :-15.96 Mean :131.9
3rd Qu.:0.0000000 3rd Qu.:28.48 3rd Qu.:-15.39 3rd Qu.: 64.0
Max. :2.0000000 Max. :28.95 Max. :-13.60 Max. :632.0
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. :164 Min. : 65 Min. : 0.00 Min. :0
1st Qu.: 6.000 1st Qu.:242 1st Qu.:129 1st Qu.: 1.00 1st Qu.:0
Median : 7.000 Median :274 Median :154 Median : 6.00 Median :0
Mean : 7.206 Mean :272 Mean :155 Mean : 10.92 Mean :0
3rd Qu.: 8.000 3rd Qu.:302 3rd Qu.:181 3rd Qu.: 15.00 3rd Qu.:0
Max. :12.000 Max. :403 Max. :254 Max. :422.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :35.28 Min. :-8.6494 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:38.88 1st Qu.:-4.8458 1st Qu.: 35.0
Median : 0.00000 Median :40.93 Median :-2.0392 Median : 127.0
Mean : 0.00361 Mean :40.46 Mean :-2.2614 Mean : 300.7
3rd Qu.: 0.00000 3rd Qu.:42.07 3rd Qu.: 0.5706 3rd Qu.: 541.0
Max. :38.00000 Max. :43.57 Max. : 4.2156 Max. :1894.0
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. :-53.00 Min. :-121.0 Min. : 0.00
1st Qu.: 4.000 1st Qu.: 30.00 1st Qu.: -31.0 1st Qu.: 17.00
Median : 6.000 Median : 74.00 Median : 8.0 Median : 30.00
Mean : 6.541 Mean : 82.34 Mean : 12.7 Mean : 34.69
3rd Qu.:10.000 3rd Qu.:133.00 3rd Qu.: 58.0 3rd Qu.: 47.00
Max. :12.000 Max. :229.00 Max. : 134.0 Max. :180.00
nevada prof_nieve longitud latitud altitud
Min. :0 Min. : 0.00 Min. :40.78 Min. :-4.0103 Min. :1405
1st Qu.:0 1st Qu.: 0.00 1st Qu.:40.78 1st Qu.:-4.0103 1st Qu.:1894
Median :0 Median : 0.00 Median :42.38 Median : 0.8842 Median :2143
Mean :0 Mean : 14.14 Mean :41.95 Mean :-0.2193 Mean :2110
3rd Qu.:0 3rd Qu.: 0.00 3rd Qu.:42.53 3rd Qu.: 1.5242 3rd Qu.:2316
Max. :0 Max. :1834.00 Max. :42.77 Max. : 2.4378 Max. :2535
if (!empty_nodes) summary(df.cluster06)
fecha_cnt tmax tmin precip
Min. : 7.00 Min. : 8.0 Min. :-110.00 Min. : 0.00
1st Qu.:10.00 1st Qu.:129.0 1st Qu.: 41.00 1st Qu.: 6.00
Median :11.00 Median :166.0 Median : 73.00 Median : 15.00
Mean :10.97 Mean :164.8 Mean : 71.61 Mean : 21.91
3rd Qu.:12.00 3rd Qu.:200.0 3rd Qu.: 102.00 3rd Qu.: 30.00
Max. :12.00 Max. :284.0 Max. : 187.00 Max. :299.00
nevada prof_nieve longitud latitud
Min. :0.0000000 Min. : 0.00000 Min. :35.28 Min. :-8.6494
1st Qu.:0.0000000 1st Qu.: 0.00000 1st Qu.:38.99 1st Qu.:-4.8500
Median :0.0000000 Median : 0.00000 Median :40.96 Median :-2.4544
Mean :0.0004291 Mean : 0.04915 Mean :40.55 Mean :-2.3567
3rd Qu.:0.0000000 3rd Qu.: 0.00000 3rd Qu.:42.08 3rd Qu.: 0.4942
Max. :3.0000000 Max. :59.00000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 47.0
Median : 261.0
Mean : 377.3
3rd Qu.: 667.0
Max. :1572.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1], dim(df.cluster06)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05", "cluster06"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.hist(df.cluster06)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster06)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
df.cluster06.grouped <- mpr.group_by_geo(df.cluster06)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster06.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=8)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=8)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
df.cluster06 <- subset(df, cluster==6)
df.cluster07 <- subset(df, cluster==7)
df.cluster08 <- subset(df, cluster==8)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster06 <- select(df.cluster06, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster07 <- select(df.cluster07, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster08 <- select(df.cluster08, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 13 Min. :-33.00 Min. : 0.00 Min. :0
1st Qu.: 4.000 1st Qu.: 94 1st Qu.: 23.00 1st Qu.: 0.00 1st Qu.:0
Median : 7.000 Median :128 Median : 50.00 Median : 3.00 Median :0
Mean : 6.603 Mean :138 Mean : 60.53 Mean : 11.63 Mean :0
3rd Qu.:10.000 3rd Qu.:183 3rd Qu.: 98.00 3rd Qu.: 14.00 3rd Qu.:0
Max. :12.000 Max. :253 Max. :159.00 Max. :309.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :28.31 Min. :-16.5 Min. :2371
1st Qu.: 0.0000 1st Qu.:28.31 1st Qu.:-16.5 1st Qu.:2371
Median : 0.0000 Median :28.31 Median :-16.5 Median :2371
Mean : 0.1753 Mean :28.31 Mean :-16.5 Mean :2371
3rd Qu.: 0.0000 3rd Qu.:28.31 3rd Qu.:-16.5 3rd Qu.:2371
Max. :46.0000 Max. :28.31 Max. :-16.5 Max. :2371
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip nevada
Min. :1.000 Min. :100.0 Min. :-17.0 Min. : 0.00 Min. :0
1st Qu.:2.000 1st Qu.:167.0 1st Qu.: 76.0 1st Qu.: 3.00 1st Qu.:0
Median :3.000 Median :191.0 Median :101.0 Median : 11.00 Median :0
Mean :3.174 Mean :196.7 Mean :100.7 Mean : 15.73 Mean :0
3rd Qu.:4.000 3rd Qu.:224.0 3rd Qu.:125.0 3rd Qu.: 22.00 3rd Qu.:0
Max. :7.000 Max. :307.0 Max. :191.0 Max. :259.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :35.28 Min. :-6.949 Min. : 1.00
1st Qu.: 0.00000 1st Qu.:36.50 1st Qu.:-6.332 1st Qu.: 19.00
Median : 0.00000 Median :36.83 Median :-5.616 Median : 32.00
Mean : 0.01769 Mean :36.92 Mean :-5.389 Mean : 75.78
3rd Qu.: 0.00000 3rd Qu.:37.26 3rd Qu.:-4.846 3rd Qu.: 90.00
Max. :34.00000 Max. :39.47 Max. :-1.169 Max. :582.00
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip
Min. :1.000 Min. : -4.0 Min. :-89.00 Min. : 0.00
1st Qu.:2.000 1st Qu.:122.0 1st Qu.: 24.00 1st Qu.: 6.00
Median :3.000 Median :152.0 Median : 52.00 Median : 13.00
Mean :2.831 Mean :151.2 Mean : 48.54 Mean : 18.61
3rd Qu.:4.000 3rd Qu.:179.0 3rd Qu.: 75.00 3rd Qu.: 25.00
Max. :7.000 Max. :282.0 Max. :143.00 Max. :371.00
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.0000 Min. :37.13 Min. :-8.6494
1st Qu.:0.000000 1st Qu.: 0.0000 1st Qu.:40.41 1st Qu.:-4.1153
Median :0.000000 Median : 0.0000 Median :41.52 Median :-2.4831
Mean :0.000713 Mean : 0.1107 Mean :41.28 Mean :-2.3430
3rd Qu.:0.000000 3rd Qu.: 0.0000 3rd Qu.:42.44 3rd Qu.: 0.4914
Max. :6.000000 Max. :75.0000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 85.0
Median : 508.0
Mean : 459.7
3rd Qu.: 704.0
Max. :1572.0
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. : 87.0 Min. : 64.0 Min. : 0.000 Min. :0
1st Qu.: 3.00 1st Qu.:212.0 1st Qu.:150.0 1st Qu.: 0.000 1st Qu.:0
Median : 6.00 Median :233.0 Median :168.0 Median : 1.000 Median :0
Mean : 6.49 Mean :233.8 Mean :169.3 Mean : 6.536 Mean :0
3rd Qu.: 9.00 3rd Qu.:259.0 3rd Qu.:196.0 3rd Qu.: 7.000 3rd Qu.:0
Max. :12.00 Max. :356.0 Max. :244.0 Max. :145.000 Max. :0
prof_nieve longitud latitud altitud
Min. :0.0000000 Min. :27.82 Min. :-17.89 Min. : 14.0
1st Qu.:0.0000000 1st Qu.:28.05 1st Qu.:-16.56 1st Qu.: 25.0
Median :0.0000000 Median :28.46 Median :-16.26 Median : 33.0
Mean :0.0003511 Mean :28.38 Mean :-15.96 Mean :131.9
3rd Qu.:0.0000000 3rd Qu.:28.48 3rd Qu.:-15.39 3rd Qu.: 64.0
Max. :2.0000000 Max. :28.95 Max. :-13.60 Max. :632.0
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. :164 Min. : 65 Min. : 0.00 Min. :0
1st Qu.: 6.000 1st Qu.:242 1st Qu.:129 1st Qu.: 1.00 1st Qu.:0
Median : 7.000 Median :274 Median :154 Median : 6.00 Median :0
Mean : 7.206 Mean :272 Mean :155 Mean : 10.92 Mean :0
3rd Qu.: 8.000 3rd Qu.:302 3rd Qu.:181 3rd Qu.: 15.00 3rd Qu.:0
Max. :12.000 Max. :403 Max. :254 Max. :422.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :35.28 Min. :-8.6494 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:38.88 1st Qu.:-4.8458 1st Qu.: 35.0
Median : 0.00000 Median :40.93 Median :-2.0392 Median : 127.0
Mean : 0.00361 Mean :40.46 Mean :-2.2614 Mean : 300.7
3rd Qu.: 0.00000 3rd Qu.:42.07 3rd Qu.: 0.5706 3rd Qu.: 541.0
Max. :38.00000 Max. :43.57 Max. : 4.2156 Max. :1894.0
if (!empty_nodes) summary(df.cluster06)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. :-53.00 Min. :-121.0 Min. : 0.00
1st Qu.: 4.000 1st Qu.: 30.00 1st Qu.: -31.0 1st Qu.: 17.00
Median : 6.000 Median : 74.00 Median : 8.0 Median : 30.00
Mean : 6.541 Mean : 82.34 Mean : 12.7 Mean : 34.69
3rd Qu.:10.000 3rd Qu.:133.00 3rd Qu.: 58.0 3rd Qu.: 47.00
Max. :12.000 Max. :229.00 Max. : 134.0 Max. :180.00
nevada prof_nieve longitud latitud altitud
Min. :0 Min. : 0.00 Min. :40.78 Min. :-4.0103 Min. :1405
1st Qu.:0 1st Qu.: 0.00 1st Qu.:40.78 1st Qu.:-4.0103 1st Qu.:1894
Median :0 Median : 0.00 Median :42.38 Median : 0.8842 Median :2143
Mean :0 Mean : 14.14 Mean :41.95 Mean :-0.2193 Mean :2110
3rd Qu.:0 3rd Qu.: 0.00 3rd Qu.:42.53 3rd Qu.: 1.5242 3rd Qu.:2316
Max. :0 Max. :1834.00 Max. :42.77 Max. : 2.4378 Max. :2535
if (!empty_nodes) summary(df.cluster07)
fecha_cnt tmax tmin precip
Min. : 7.00 Min. : 8.0 Min. :-110.00 Min. : 0.00
1st Qu.:10.00 1st Qu.:110.0 1st Qu.: 23.00 1st Qu.: 7.00
Median :11.00 Median :140.0 Median : 54.00 Median : 16.00
Mean :10.96 Mean :144.7 Mean : 51.45 Mean : 23.64
3rd Qu.:12.00 3rd Qu.:179.0 3rd Qu.: 82.00 3rd Qu.: 31.00
Max. :12.00 Max. :265.0 Max. : 140.00 Max. :299.00
nevada prof_nieve longitud latitud
Min. :0.0000000 Min. : 0.00000 Min. :37.18 Min. :-8.649
1st Qu.:0.0000000 1st Qu.: 0.00000 1st Qu.:40.48 1st Qu.:-5.498
Median :0.0000000 Median : 0.00000 Median :41.70 Median :-3.764
Mean :0.0008031 Mean : 0.06487 Mean :41.53 Mean :-3.621
3rd Qu.:0.0000000 3rd Qu.: 0.00000 3rd Qu.:42.59 3rd Qu.:-1.885
Max. :3.0000000 Max. :40.00000 Max. :43.57 Max. : 2.482
altitud
Min. : 4.0
1st Qu.: 442.0
Median : 639.0
Mean : 607.5
3rd Qu.: 846.0
Max. :1572.0
if (!empty_nodes) summary(df.cluster08)
fecha_cnt tmax tmin precip nevada
Min. : 8.00 Min. : 68.0 Min. :-29.00 Min. : 0.00 Min. :0
1st Qu.:10.00 1st Qu.:161.0 1st Qu.: 66.00 1st Qu.: 4.00 1st Qu.:0
Median :11.00 Median :185.0 Median : 96.00 Median : 13.00 Median :0
Mean :10.97 Mean :187.7 Mean : 94.73 Mean : 19.92 Mean :0
3rd Qu.:12.00 3rd Qu.:218.0 3rd Qu.:124.00 3rd Qu.: 28.00 3rd Qu.:0
Max. :12.00 Max. :284.0 Max. :187.00 Max. :206.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :35.28 Min. :-6.9492 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:37.78 1st Qu.:-3.7892 1st Qu.: 17.0
Median : 0.00000 Median :39.49 Median : 0.4731 Median : 68.6
Mean : 0.03112 Mean :39.44 Mean :-0.9058 Mean :113.2
3rd Qu.: 0.00000 3rd Qu.:41.42 3rd Qu.: 1.3842 3rd Qu.:158.0
Max. :59.00000 Max. :43.36 Max. : 4.2156 Max. :691.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1], dim(df.cluster06)[1], dim(df.cluster07)[1], dim(df.cluster08)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05", "cluster06", "cluster07", "cluster08"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.hist(df.cluster06)
if (!empty_nodes) mpr.hist(df.cluster07)
if (!empty_nodes) mpr.hist(df.cluster08)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster06)
if (!empty_nodes) mpr.boxplot(df.cluster07)
if (!empty_nodes) mpr.boxplot(df.cluster08)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
df.cluster06.grouped <- mpr.group_by_geo(df.cluster06)
df.cluster07.grouped <- mpr.group_by_geo(df.cluster07)
df.cluster08.grouped <- mpr.group_by_geo(df.cluster08)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster06.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster07.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster08.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=10)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=10)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
df.cluster06 <- subset(df, cluster==6)
df.cluster07 <- subset(df, cluster==7)
df.cluster08 <- subset(df, cluster==8)
df.cluster09 <- subset(df, cluster==9)
df.cluster10 <- subset(df, cluster==10)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster06 <- select(df.cluster06, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster07 <- select(df.cluster07, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster08 <- select(df.cluster08, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster09 <- select(df.cluster09, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster10 <- select(df.cluster10, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. : 13 Min. :-33.00 Min. : 0.00 Min. :0
1st Qu.: 4.000 1st Qu.: 94 1st Qu.: 23.00 1st Qu.: 0.00 1st Qu.:0
Median : 7.000 Median :128 Median : 50.00 Median : 3.00 Median :0
Mean : 6.603 Mean :138 Mean : 60.53 Mean : 11.63 Mean :0
3rd Qu.:10.000 3rd Qu.:183 3rd Qu.: 98.00 3rd Qu.: 14.00 3rd Qu.:0
Max. :12.000 Max. :253 Max. :159.00 Max. :309.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :28.31 Min. :-16.5 Min. :2371
1st Qu.: 0.0000 1st Qu.:28.31 1st Qu.:-16.5 1st Qu.:2371
Median : 0.0000 Median :28.31 Median :-16.5 Median :2371
Mean : 0.1753 Mean :28.31 Mean :-16.5 Mean :2371
3rd Qu.: 0.0000 3rd Qu.:28.31 3rd Qu.:-16.5 3rd Qu.:2371
Max. :46.0000 Max. :28.31 Max. :-16.5 Max. :2371
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip nevada
Min. :1.000 Min. :100.0 Min. :-17.0 Min. : 0.00 Min. :0
1st Qu.:2.000 1st Qu.:167.0 1st Qu.: 76.0 1st Qu.: 3.00 1st Qu.:0
Median :3.000 Median :191.0 Median :101.0 Median : 11.00 Median :0
Mean :3.174 Mean :196.7 Mean :100.7 Mean : 15.73 Mean :0
3rd Qu.:4.000 3rd Qu.:224.0 3rd Qu.:125.0 3rd Qu.: 22.00 3rd Qu.:0
Max. :7.000 Max. :307.0 Max. :191.0 Max. :259.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :35.28 Min. :-6.949 Min. : 1.00
1st Qu.: 0.00000 1st Qu.:36.50 1st Qu.:-6.332 1st Qu.: 19.00
Median : 0.00000 Median :36.83 Median :-5.616 Median : 32.00
Mean : 0.01769 Mean :36.92 Mean :-5.389 Mean : 75.78
3rd Qu.: 0.00000 3rd Qu.:37.26 3rd Qu.:-4.846 3rd Qu.: 90.00
Max. :34.00000 Max. :39.47 Max. :-1.169 Max. :582.00
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip
Min. :1.000 Min. : -4.0 Min. :-89.00 Min. : 0.00
1st Qu.:2.000 1st Qu.:122.0 1st Qu.: 24.00 1st Qu.: 6.00
Median :3.000 Median :152.0 Median : 52.00 Median : 13.00
Mean :2.831 Mean :151.2 Mean : 48.54 Mean : 18.61
3rd Qu.:4.000 3rd Qu.:179.0 3rd Qu.: 75.00 3rd Qu.: 25.00
Max. :7.000 Max. :282.0 Max. :143.00 Max. :371.00
nevada prof_nieve longitud latitud
Min. :0.000000 Min. : 0.0000 Min. :37.13 Min. :-8.6494
1st Qu.:0.000000 1st Qu.: 0.0000 1st Qu.:40.41 1st Qu.:-4.1153
Median :0.000000 Median : 0.0000 Median :41.52 Median :-2.4831
Mean :0.000713 Mean : 0.1107 Mean :41.28 Mean :-2.3430
3rd Qu.:0.000000 3rd Qu.: 0.0000 3rd Qu.:42.44 3rd Qu.: 0.4914
Max. :6.000000 Max. :75.0000 Max. :43.57 Max. : 4.2156
altitud
Min. : 1.0
1st Qu.: 85.0
Median : 508.0
Mean : 459.7
3rd Qu.: 704.0
Max. :1572.0
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. : 87.0 Min. : 64.0 Min. : 0.000 Min. :0
1st Qu.: 3.00 1st Qu.:212.0 1st Qu.:150.0 1st Qu.: 0.000 1st Qu.:0
Median : 6.00 Median :233.0 Median :168.0 Median : 1.000 Median :0
Mean : 6.49 Mean :233.8 Mean :169.3 Mean : 6.536 Mean :0
3rd Qu.: 9.00 3rd Qu.:259.0 3rd Qu.:196.0 3rd Qu.: 7.000 3rd Qu.:0
Max. :12.00 Max. :356.0 Max. :244.0 Max. :145.000 Max. :0
prof_nieve longitud latitud altitud
Min. :0.0000000 Min. :27.82 Min. :-17.89 Min. : 14.0
1st Qu.:0.0000000 1st Qu.:28.05 1st Qu.:-16.56 1st Qu.: 25.0
Median :0.0000000 Median :28.46 Median :-16.26 Median : 33.0
Mean :0.0003511 Mean :28.38 Mean :-15.96 Mean :131.9
3rd Qu.:0.0000000 3rd Qu.:28.48 3rd Qu.:-15.39 3rd Qu.: 64.0
Max. :2.0000000 Max. :28.95 Max. :-13.60 Max. :632.0
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. :171.0 Min. : 65.0 Min. : 0.00 Min. :0
1st Qu.: 5.000 1st Qu.:246.0 1st Qu.:134.0 1st Qu.: 2.00 1st Qu.:0
Median : 7.000 Median :276.0 Median :165.0 Median : 7.00 Median :0
Mean : 6.695 Mean :270.7 Mean :161.2 Mean : 11.26 Mean :0
3rd Qu.: 8.000 3rd Qu.:298.0 3rd Qu.:189.0 3rd Qu.: 16.00 3rd Qu.:0
Max. :12.000 Max. :386.0 Max. :254.0 Max. :320.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :37.79 Min. :-2.9056 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:39.48 1st Qu.: 0.3264 1st Qu.: 25.0
Median : 0.00000 Median :41.15 Median : 0.6350 Median : 71.0
Mean : 0.00338 Mean :40.46 Mean : 0.8364 Mean :148.7
3rd Qu.: 0.00000 3rd Qu.:41.66 3rd Qu.: 1.9625 3rd Qu.:247.0
Max. :38.00000 Max. :43.36 Max. : 4.2156 Max. :953.0
if (!empty_nodes) summary(df.cluster06)
fecha_cnt tmax tmin precip nevada
Min. : 4.000 Min. :164.0 Min. : 67.0 Min. : 0.00 Min. :0
1st Qu.: 7.000 1st Qu.:240.0 1st Qu.:127.0 1st Qu.: 1.00 1st Qu.:0
Median : 8.000 Median :272.0 Median :148.0 Median : 6.00 Median :0
Mean : 7.588 Mean :272.9 Mean :150.4 Mean : 10.67 Mean :0
3rd Qu.: 9.000 3rd Qu.:305.0 3rd Qu.:172.0 3rd Qu.: 15.00 3rd Qu.:0
Max. :11.000 Max. :403.0 Max. :250.0 Max. :422.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :35.28 Min. :-8.649 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:37.84 1st Qu.:-5.879 1st Qu.: 52.0
Median : 0.00000 Median :40.84 Median :-4.127 Median : 370.0
Mean : 0.00378 Mean :40.46 Mean :-4.573 Mean : 414.1
3rd Qu.: 0.00000 3rd Qu.:42.59 3rd Qu.:-3.450 3rd Qu.: 687.0
Max. :35.00000 Max. :43.57 Max. : 2.438 Max. :1894.0
if (!empty_nodes) summary(df.cluster07)
fecha_cnt tmax tmin precip nevada
Min. : 2.000 Min. :-20.0 Min. :-80.00 Min. : 0.00 Min. :0
1st Qu.: 7.000 1st Qu.: 68.0 1st Qu.: 8.00 1st Qu.: 16.00 1st Qu.:0
Median : 9.000 Median :113.0 Median : 42.00 Median : 28.00 Median :0
Mean : 8.622 Mean :110.6 Mean : 38.76 Mean : 32.82 Mean :0
3rd Qu.:11.000 3rd Qu.:155.0 3rd Qu.: 77.00 3rd Qu.: 43.00 3rd Qu.:0
Max. :12.000 Max. :229.0 Max. :134.00 Max. :171.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :40.78 Min. :-4.0103 Min. :1405
1st Qu.: 0.000 1st Qu.:40.78 1st Qu.:-4.0103 1st Qu.:1894
Median : 0.000 Median :42.29 Median : 0.8842 Median :2143
Mean : 3.166 Mean :41.92 Mean :-0.2785 Mean :2093
3rd Qu.: 0.000 3rd Qu.:42.53 3rd Qu.: 1.5242 3rd Qu.:2316
Max. :382.000 Max. :42.77 Max. : 2.4378 Max. :2535
if (!empty_nodes) summary(df.cluster08)
fecha_cnt tmax tmin precip
Min. : 1.000 Min. :-53.0 Min. :-121.00 Min. : 0.00
1st Qu.: 2.000 1st Qu.: 9.0 1st Qu.: -52.00 1st Qu.: 19.00
Median : 3.000 Median : 31.0 Median : -34.00 Median : 34.00
Mean : 2.727 Mean : 30.6 Mean : -35.04 Mean : 38.13
3rd Qu.: 4.000 3rd Qu.: 54.0 3rd Qu.: -13.00 3rd Qu.: 52.00
Max. :12.000 Max. :120.0 Max. : 56.00 Max. :180.00
nevada prof_nieve longitud latitud altitud
Min. :0 Min. : 0.00 Min. :40.78 Min. :-4.0103 Min. :1405
1st Qu.:0 1st Qu.: 0.00 1st Qu.:40.78 1st Qu.:-4.0103 1st Qu.:1894
Median :0 Median : 0.00 Median :42.38 Median : 0.9844 Median :2228
Mean :0 Mean : 34.26 Mean :42.00 Mean :-0.1108 Mean :2141
3rd Qu.:0 3rd Qu.: 0.00 3rd Qu.:42.53 3rd Qu.: 1.5242 3rd Qu.:2316
Max. :0 Max. :1834.00 Max. :42.77 Max. : 2.4378 Max. :2535
if (!empty_nodes) summary(df.cluster09)
fecha_cnt tmax tmin precip
Min. : 7.00 Min. : 8.0 Min. :-110.00 Min. : 0.00
1st Qu.:10.00 1st Qu.:110.0 1st Qu.: 23.00 1st Qu.: 7.00
Median :11.00 Median :140.0 Median : 54.00 Median : 16.00
Mean :10.96 Mean :144.7 Mean : 51.45 Mean : 23.64
3rd Qu.:12.00 3rd Qu.:179.0 3rd Qu.: 82.00 3rd Qu.: 31.00
Max. :12.00 Max. :265.0 Max. : 140.00 Max. :299.00
nevada prof_nieve longitud latitud
Min. :0.0000000 Min. : 0.00000 Min. :37.18 Min. :-8.649
1st Qu.:0.0000000 1st Qu.: 0.00000 1st Qu.:40.48 1st Qu.:-5.498
Median :0.0000000 Median : 0.00000 Median :41.70 Median :-3.764
Mean :0.0008031 Mean : 0.06487 Mean :41.53 Mean :-3.621
3rd Qu.:0.0000000 3rd Qu.: 0.00000 3rd Qu.:42.59 3rd Qu.:-1.885
Max. :3.0000000 Max. :40.00000 Max. :43.57 Max. : 2.482
altitud
Min. : 4.0
1st Qu.: 442.0
Median : 639.0
Mean : 607.5
3rd Qu.: 846.0
Max. :1572.0
if (!empty_nodes) summary(df.cluster10)
fecha_cnt tmax tmin precip nevada
Min. : 8.00 Min. : 68.0 Min. :-29.00 Min. : 0.00 Min. :0
1st Qu.:10.00 1st Qu.:161.0 1st Qu.: 66.00 1st Qu.: 4.00 1st Qu.:0
Median :11.00 Median :185.0 Median : 96.00 Median : 13.00 Median :0
Mean :10.97 Mean :187.7 Mean : 94.73 Mean : 19.92 Mean :0
3rd Qu.:12.00 3rd Qu.:218.0 3rd Qu.:124.00 3rd Qu.: 28.00 3rd Qu.:0
Max. :12.00 Max. :284.0 Max. :187.00 Max. :206.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :35.28 Min. :-6.9492 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:37.78 1st Qu.:-3.7892 1st Qu.: 17.0
Median : 0.00000 Median :39.49 Median : 0.4731 Median : 68.6
Mean : 0.03112 Mean :39.44 Mean :-0.9058 Mean :113.2
3rd Qu.: 0.00000 3rd Qu.:41.42 3rd Qu.: 1.3842 3rd Qu.:158.0
Max. :59.00000 Max. :43.36 Max. : 4.2156 Max. :691.0
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1], dim(df.cluster06)[1], dim(df.cluster07)[1], dim(df.cluster08)[1], dim(df.cluster09)[1], dim(df.cluster10)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05", "cluster06", "cluster07", "cluster08", "cluster09", "cluster10"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.hist(df.cluster06)
if (!empty_nodes) mpr.hist(df.cluster07)
if (!empty_nodes) mpr.hist(df.cluster08)
if (!empty_nodes) mpr.hist(df.cluster09)
if (!empty_nodes) mpr.hist(df.cluster10)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster06)
if (!empty_nodes) mpr.boxplot(df.cluster07)
if (!empty_nodes) mpr.boxplot(df.cluster08)
if (!empty_nodes) mpr.boxplot(df.cluster09)
if (!empty_nodes) mpr.boxplot(df.cluster10)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
df.cluster06.grouped <- mpr.group_by_geo(df.cluster06)
df.cluster07.grouped <- mpr.group_by_geo(df.cluster07)
df.cluster08.grouped <- mpr.group_by_geo(df.cluster08)
df.cluster09.grouped <- mpr.group_by_geo(df.cluster09)
df.cluster10.grouped <- mpr.group_by_geo(df.cluster10)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster06.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster07.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster08.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster09.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster10.grouped)